//
//  KVEmoticonPackgeModel.swift
//  KVEmoticon
//
//  Created by 李康卫 on 16/7/29.
//  Copyright © 2016年 李康卫. All rights reserved.
//

import UIKit

class KVEmoticonPackgeModel: NSObject {
    ///文件目录名称
    var id: String?
    ///包名
    var group_name_cn: String?
    ///图片数组
    var emoticons = [KVEmoticonModel]()
    ///将emoticons分页
    var emoticonsOfPage: [[KVEmoticonModel]] = [[KVEmoticonModel]]()
    ///模型管理者传入参数给模型如值
    init(id: String,group_name_cn: String,emoticons: [KVEmoticonModel]) {
        self.id = id
        self.group_name_cn = group_name_cn
        self.emoticons = emoticons
        super.init()
        //初始化后分页
       splitedPageOfEmoticons()
    }
    private func splitedPageOfEmoticons(){
        //总页数： 表情总数 + 一页总数 - 1 / 一页总数
        let pageCount = (self.emoticons.count + emoticonsCountOfPage - 1)/emoticonsCountOfPage
        //定义空数组保存
        //先判断是否为0
        if pageCount == 0 {
            //第常用组
            emoticonsOfPage.append([KVEmoticonModel]())
        } else {
            var lenght = 20
            for var i = 0; i < pageCount; i++ {
                let location = i*emoticonsCountOfPage
                //如果是最后一页做特殊处理
                if i == pageCount - 1 {
                    lenght = self.emoticons.count - location
                }
                let range = NSRange(location: location, length: lenght)
                //将emoticons切成每一页的数组
                let emotionArr = (emoticons as NSArray).subarrayWithRange(range) as! [KVEmoticonModel]
                emoticonsOfPage.append(emotionArr)
                
            }
        }
   
        
    }
    
    override var description: String {
        get {
            return "\n\n\n文件目录名称：\(id)\n,包名：\(group_name_cn)\n,图片数组：\(emoticonsOfPage)\n"
        }
    }
}
